define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'swiper/index' + location.search,
                    add_url: 'swiper/add',
                    edit_url: 'swiper/edit',
                    del_url: 'swiper/del',
                    multi_url: 'swiper/multi',
                    import_url: 'swiper/import',
                    table: 'swiper',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                searchFormVisible: false,
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {
                            field: 'id', title: __('编号'), formatter: function (value, row, index) {
                                return index + 1;
                            },
                            searchable: false
                        },
                        {
                            field: 'img_url',
                            searchable: false,
                            title: __('图片预览'),
                            operate: 'LIKE',
                            formatter: Table.api.formatter.images
                        },
                        {
                            field: 'img_url',
                            searchable: false,
                            title: __('图片地址'),
                            operate: 'LIKE',
                            formatter: Table.api.formatter.url
                        },
                        {
                            field: 'target_url',
                            searchable: false,
                            title: __('跳转地址'),
                            operate: 'LIKE',
                            formatter: Table.api.formatter.url
                        },
                        {
                            field: 'a_time',
                            title: __('A_time'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'u_time',
                            title: __('U_time'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'remark',
                            searchable: false,
                            title: __('Remark')
                        },
                        {
                            field: 'status',
                            title: __('Status'),
                            formatter: Table.api.formatter.normal,
                            searchList: {'1': __('启用'), '2': __('关闭')}
                        },
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
